package com.app.qbake.module.mine.adapter.delegate;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.qbake.R;
import com.app.qbake.module.mine.layout.GetEditGoodsLayout;
import com.app.qbake.module.publish.activity.PublishGoodsActivity;
import com.wind.base.adapter.BaseAdapterDelegate;
import com.wind.base.adapter.DisplayItem;
import com.wind.base.utils.ViewInflater;
import com.wind.data.mine.GetEditGoodsResponse;
import com.wind.data.square.bean.Goods;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wind on 2018/10/19.
 */

public class GoodsPublishDisableDelegate extends BaseAdapterDelegate<GoodsPublishDisableDelegate.ViewHolder> {

    GetEditGoodsLayout mGetEditGoodsLayout;
    public GoodsPublishDisableDelegate(Activity activity, int layoutRes) {
        super(activity, layoutRes);
        mGetEditGoodsLayout=new GetEditGoodsLayout(mActivity, new GetEditGoodsLayout.OnGetEditGoodsListener() {
            @Override
            public void onGetEditGoods(GetEditGoodsResponse response) {
                PublishGoodsActivity.start(mActivity,response.getData());
            }
        });
    }

    @Override
    protected ViewHolder onCreateViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    protected boolean isForViewType(@NonNull List<DisplayItem> items, int position) {
        Goods goods = (Goods) items.get(position);
        return goods.getStatus() ==  Goods.STATUS_DISABLE;
    }

    @Override
    protected void onBindViewHolder(@NonNull List<DisplayItem> items, int position, @NonNull RecyclerView.ViewHolder holder, @NonNull List<Object> payloads) {
        final Goods goods = (Goods) items.get(position);
        ViewHolder vh = (ViewHolder) holder;
        ViewInflater.inflateImage(vh.iv, goods.getImage_url());
        ViewInflater.inflateText(vh.tv_desc, goods.getTitle());
        ViewInflater.inflateText(vh.tv_price, goods.getPrice());
        //int status = goods.getStatus();
        /*switch (status) {
            case Goods.STATUS_PASSED:
                ViewInflater.inflateText(vh.tv_status,"已发布");
                vh.tv_down.setVisibility(View.VISIBLE);
                break;
            case Goods.STATUS_PUBLISHING:
                ViewInflater.inflateText(vh.tv_status,"发布中...");
                vh.tv_down.setVisibility(View.GONE);
                break;
            case Goods.STATUS_CHECK_FAILED:
                ViewInflater.inflateText(vh.tv_status,"审核失败");
                vh.tv_down.setVisibility(View.GONE);
                break;

        }*/

        vh.tv_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               mGetEditGoodsLayout.get(goods.getId());
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv_desc)
        TextView tv_desc;
        @BindView(R.id.tv_status)
        TextView tv_status;
        @BindView(R.id.tv_price)
        TextView tv_price;
        @BindView(R.id.tv_edit)
        TextView tv_edit;
        @BindView(R.id.tv_down)
        TextView tv_down;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
